package com.plate.modules.system.controller;

import com.plate.common.core.constants.RequestConstant;
import com.plate.common.core.constants.SysConstant;
import com.plate.common.core.result.Result;
import com.plate.common.web.domain.LoginVal;
import com.plate.common.web.utils.RequestContextUtils;
import com.plate.modules.system.domain.po.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author jiaxd
 * @Date 2023年11月22日 23:34
 * @Version 1.0
 */

@RestController
@RequestMapping("/sys")
public class LoginController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @PostMapping(value = "/logout")
    public Result logOut(HttpServletRequest request) {
        LoginVal loginVal = (LoginVal) RequestContextUtils.getRequest().getAttribute(RequestConstant.LOGIN_VAL_ATTRIBUTE);
        redisTemplate.opsForValue().set(SysConstant.JTI_KEY_PREFIX + loginVal.getJti(), "", loginVal.getExpireIn(), TimeUnit.SECONDS);
        return Result.SUCCESS();

    }

    @PostMapping(value = "/login")
    public Result login(@RequestBody SysUser sysUser) {


        return Result.SUCCESS();
    }

}
